//
// Created by 11510 on 2024/6/15.
//

#ifndef XMLPARSING_RSSREADER_H
#define XMLPARSING_RSSREADER_H
#include <iostream>
#include <vector>
#include <string>
using std::vector;
using std::string;

struct RssItem {
    string title;
    string link;
    string description;
    string content;

    RssItem(const string& title, const string& link, const string& description, const string& content);
};

class RssReader{
public:
    explicit RssReader(int capacity){
        /**
         * 易错点
         * C++：预留空间要用reserve不能写在构造方法中
         * Java：预留空间直接写在构造方法中
         */
        rss = new vector<RssItem*>();
        rss->reserve(capacity);
    }

    ~RssReader(){
        if(rss) {
            for (vector<RssItem *>::iterator it = rss->begin(); it != rss->end(); it++) {
                delete *it;
            }
            delete rss;
            rss = nullptr;
        }
    }

    void parseRss(const char* filename);//解析
    void dump(const char* filename);//输出
private:
    vector<RssItem*>* rss = nullptr;
};


#endif //XMLPARSING_RSSREADER_H
